﻿<%@ Page Language="C#" Title="Quản lý lịch trình xe bus" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="ManageSchedule.aspx.cs" Inherits="View_ManageSchedule" %>

<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>

<asp:Content runat="server" ID="BodyContent" ContentPlaceHolderID="MainContent">
    <telerik:RadScriptBlock ID="RadScriptBlock1" runat="server">
        <script type="text/javascript">

            //enter search
            function OnKeyPress(sender, eventArgs) {
                var c = eventArgs.get_keyCode();
                if (c == 13) {
                    var stringSearch = $("#<%= txtKeyWord.ClientID%>").val();
                    $("#<%= hdfSearchString.ClientID %>").val(stringSearch);
                    $("#<%=btnSearch.ClientID %>").click();
                    eventArgs.set_cancel(true);
                }
            }

            function messsage(mes) {
                alert(mes);
                return false;
            }

            function HyperLinkMap_Click() {
                var IDBusStrip = window.$find("<%= ddlNameBusTrip.ClientID %>").get_value();
                var Direction = window.$find("<%= ddlDirection.ClientID %>").get_value();
                if (Direction == "Chiều đi") {
                    Direction = 0;
                } else {
                    Direction = 1;
                }
                var link = "MapViewChoose.aspx?IDBusStrip=" + IDBusStrip + "&Direction=" + Direction;
                var newWindow = window.open(link, '_blank');
                newWindow.focus();
                return false;
            }

            function checkAddNewClick() {
                if ($("#" + $("#<%=txtStationNameHDF.ClientID %>").val()).val() == 'Vui lòng chọn điểm từ bản đồ..'
                   && $("#" + $("#<%=txtLongitudehdf.ClientID %>").val()).val() == 'Vui lòng chọn điểm từ bản đồ..'
                    && $("#" + $("#<%=txtLatitudehdf.ClientID %>").val()).val() == 'Vui lòng chọn điểm từ bản đồ..') {
                    var r = confirm("Mời bạn nhập dữ liệu từ bản đồ!");
                    if (r == true) {
                        HyperLinkMap_Click();
                    }
                    else {
                        return false;
                    }
                    return false;
                }
                else {
                    return true;
                }
            }

            function refresh_data(name, lat, long) {
                var masterTable = $find("<%= rdgBusSchedule.ClientID %>").get_masterTableView();
                var insert = masterTable.get_isItemInserted();
                if (insert) {
                    $("#" + $("#<%=txtStationNameHDF.ClientID %>").val()).val(name);
                    $("#" + $("#<%=txtLongitudehdf.ClientID %>").val()).val(long);
                    $("#" + $("#<%=txtLatitudehdf.ClientID %>").val()).val(lat);
                } else {
                    var editedItemsArray = masterTable.get_editItems();
                    var editItem = editedItemsArray[0];
                    var txtStationName = $(editItem.get_editFormItem()).find("input[id*='txtStationName']").get(0).id;
                    var txtLongitude = $(editItem.get_editFormItem()).find("input[id*='txtLongitude']").get(0).id;
                    var txtLatitude = $(editItem.get_editFormItem()).find("input[id*='txtLatitude']").get(0).id;

                    $("#" + txtStationName).val(name);
                    $("#" + txtLongitude).val(long);
                    $("#" + txtLatitude).val(lat);
                }
                return false;
            }
        </script>
    </telerik:RadScriptBlock>
    <link href="../Style/StyleCommon.css" rel="stylesheet" type="text/css" />
    <link href="../Style/StyleCommon.css" rel="stylesheet" />
    <script language="javascript" type="text/javascript" src="../Scripts/Common.js"> </script>

    <div class="tabHeader">
        <span class="iconHomeBox">
            <img src="../Content/system/stop_icon.png" style="width: 35px; height: 35px; position: absolute" title="Quản lý lịch trình" />
            <div class="tabHeaderText" style="padding-top: 5px; padding-left: 40px;">
                <asp:Label ID="Label1" runat="server" Text="Quản lý bến đỗ" />
            </div>
        </span>
    </div>
    <div id="tab1" class="tabContent tabDetailContent">
        <telerik:RadAjaxPanel ID="rapBusSchedule" runat="server" LoadingPanelID="loadingPanel"
            HorizontalAlign="NotSet">
            <asp:HiddenField runat="server" ID="hdfSearchString" />
            <asp:HiddenField runat="server" ID="txtStationNameHDF" />
            <asp:HiddenField runat="server" ID="txtLongitudehdf" />
            <asp:HiddenField runat="server" ID="txtLatitudehdf" />

            <table style="width: 50%;">
                <tr style="text-align: left">
                    <td style="width: 130px;">Chuyến bus : 
                    </td>
                    <td>
                        <telerik:RadComboBox Filter="Contains" ID="ddlNameBusTrip" runat="server" AutoPostBack="true"
                            Skin="Office2010Blue" Width="155px" OnSelectedIndexChanged="ddlNameBusTrip_SelectedIndexChanged">
                        </telerik:RadComboBox>
                    </td>
                </tr>
                <tr style="text-align: left">
                    <td>Chiều :
                    </td>
                    <td>
                        <telerik:RadComboBox Filter="Contains" ID="ddlDirection" runat="server" AutoPostBack="true"
                            Skin="Office2010Blue" Width="155px" OnSelectedIndexChanged="ddlDirection_SelectedIndexChanged">
                        </telerik:RadComboBox>
                    </td>
                </tr>
            </table>

            <div id="message">
            </div>
            <table style="width: 100%">
                <tr style="text-align: left">
                    <td>
                        <table>
                            <tr>
                                <td>
                                    <telerik:RadTextBox ID="txtKeyWord" Height="25px" runat="server" EmptyMessage="Nhập từ khóa tìm kiếm" LabelCssClass="" Width="200px">
                                        <ClientEvents OnKeyPress="OnKeyPress" />
                                    </telerik:RadTextBox>
                                </td>
                                <td>
                                    <asp:Button ID="btnSearch" runat="server" CssClass="myButton" Text="Tìm kiếm" OnClick="btnSearch_Click" />
                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>
            </table>

            <telerik:RadGrid ID="rdgBusSchedule" MasterTableView-InsertItemPageIndexAction="ShowItemOnFirstPage" runat="server" AllowPaging="True" AutoGenerateColumns="False" GridLines="None" PageSize="5" Skin="Office2010Blue" OnNeedDataSource="rdgBusSchedule_NeedDataSource" OnDeleteCommand="rdgBusSchedule_DeleteCommand" OnInsertCommand="rdgBusSchedule_InsertCommand" OnItemDataBound="rdgBusSchedule_ItemDataBound" OnUpdateCommand="rdgBusSchedule_UpdateCommand">
                <ClientSettings EnableRowHoverStyle="true">
                    <Selecting AllowRowSelect="true" />
                </ClientSettings>
                <MasterTableView AllowSorting="True" CommandItemDisplay="Top" DataKeyNames="IDSchedule">
                    <Columns>
                        <telerik:GridBoundColumn DataField="STT" HeaderText="STT" UniqueName="STT">
                            <HeaderStyle HorizontalAlign="Center" Width="30px" />
                            <ItemStyle HorizontalAlign="Center" Height="40px" />
                        </telerik:GridBoundColumn>

                        <telerik:GridBoundColumn DataField="StationName" EditFormHeaderTextFormat="Tên trạm dừng:&lt;font color=red&gt;(*)&lt;/font&gt;" HeaderText="Tên trạm dừng" UniqueName="StationName">
                            <HeaderStyle HorizontalAlign="Left" Width="300px" />
                        </telerik:GridBoundColumn>

                        <telerik:GridBoundColumn DataField="Latitude" EditFormHeaderTextFormat="Vĩ độ:&lt;font color=red&gt;(*)&lt;/font&gt;" HeaderText="Vĩ độ" UniqueName="Latitude">
                            <HeaderStyle HorizontalAlign="Left" Width="100px" />
                        </telerik:GridBoundColumn>

                        <telerik:GridBoundColumn DataField="Longitude" EditFormHeaderTextFormat="Kinh độ:&lt;font color=red&gt;(*)&lt;/font&gt;" HeaderText="Kinh độ" UniqueName="Longitude">
                            <HeaderStyle HorizontalAlign="Left" Width="100px" />
                        </telerik:GridBoundColumn>

                        <telerik:GridEditCommandColumn ButtonType="ImageButton" EditImageUrl="../Images/Grid/Skins/Telerik/Edit.gif" EditText="Chỉnh sửa" InsertImageUrl="../Images/Grid/Skins/Telerik/Insert.gif" ItemStyle-Height="20px" ItemStyle-Width="20px" UniqueName="Edit">
                            <ItemStyle CssClass="editcommand" />
                            <HeaderStyle Height="20px" HorizontalAlign="Left" Width="20px" />
                        </telerik:GridEditCommandColumn>
                        <telerik:GridButtonColumn ButtonType="ImageButton" CommandName="Delete" ConfirmText="Bạn có chắc chắn muốn xóa không?" ImageUrl="../Images/Grid/Skins/Telerik/Delete.gif" ItemStyle-Height="20px" ItemStyle-Width="20px" Text="Xóa" UniqueName="Delete">
                            <ItemStyle CssClass="editcommand" />
                            <HeaderStyle Height="20px" HorizontalAlign="Left" Width="20px" />
                        </telerik:GridButtonColumn>
                    </Columns>
                    <EditFormSettings CaptionDataField="StationName" EditFormType="Template" CaptionFormatString="Chỉnh sửa cho điểm dừng {0}">
                        <FormTemplate>
                            <table style="border-collapse: collapse; width: 500px; margin-left: 20px;">
                                <tr>
                                    <td>
                                        <table style="border-collapse: collapse; width: 450px;">
                                            <tr>
                                                <td style="width: 150px;">Tên trạm dừng :
                                                </td>
                                                <td>
                                                    <asp:TextBox ID="txtStationName" Enabled="false" runat="server" Text='<%# Bind("StationName") %>' Width="300px"></asp:TextBox>
                                                </td>
                                            </tr>

                                            <tr>
                                                <td>Vĩ độ :
                                                </td>
                                                <td>
                                                    <asp:TextBox ID="txtLatitude" Enabled="false" runat="server" Text='<%# Bind("Latitude") %>' Width="300px"></asp:TextBox>
                                                </td>
                                            </tr>

                                            <tr>
                                                <td>Kinh độ :
                                                </td>
                                                <td>
                                                    <asp:TextBox ID="txtLongitude" Enabled="false" runat="server" Text='<%# Bind("Longitude") %>' Width="300px"></asp:TextBox>
                                                </td>
                                            </tr>

                                        </table>
                                    </td>
                                    <td style="align-self: center">
                                        <asp:ImageButton runat="server" ToolTip="Chọn điểm trên bản đồ!" OnClientClick="return HyperLinkMap_Click();" Width="35px" Height="35px" ID="HyperLinkMap" ImageUrl="~/Content/system/Insert-hyperlink-icon.png" />
                                    </td>
                                </tr>
                                <tr>
                                    <td colspan="2">
                                        <asp:Button ID="UpdateButton" runat="server" CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>'></asp:Button>&nbsp;
                                         <asp:Button ID="CancelButton" Text="Cancel" runat="server" CausesValidation="False"
                                             CommandName="Cancel"></asp:Button>
                                    </td>
                                </tr>
                            </table>
                        </FormTemplate>
                    </EditFormSettings>
                    <PagerStyle AlwaysVisible="True" CssClass="GridPager_Telerik" Mode="NextPrevNumericAndAdvanced" NextPageText="Next" PagerTextFormat="{4}|Displaying page {0} / {1},items {2} to {3} of {5}" PrevPageText="Previous" VerticalAlign="Middle" />
                    <CommandItemTemplate>
                        <table style="border: 0; width: 100%">
                            <tr>
                                <td style="text-align: left">
                                    <asp:LinkButton ID="lkbtnAddBusRides" runat="server" CommandName="InitInsert" Text="&lt;img style=&quot;border:0px&quot; alt=&quot;&quot; src=&quot;../Images/Grid/Skins/Telerik/AddRecord.gif&quot; /&gt; Thêm mới bến đỗ"></asp:LinkButton>
                                </td>
                            </tr>
                        </table>
                    </CommandItemTemplate>
                </MasterTableView>
            </telerik:RadGrid>

            <telerik:RadInputManager runat="server" ID="RadInputManager1">
                <telerik:TextBoxSetting EmptyMessage="Vui lòng chọn điểm từ bản đồ.." ErrorMessage="Vui lòng chọn điểm từ bản đồ..">
                    <TargetControls>
                        <telerik:TargetInput ControlID="txtStationName" />
                        <telerik:TargetInput ControlID="txtLatitude" />
                        <telerik:TargetInput ControlID="txtLongitude" />
                    </TargetControls>
                    <Validation IsRequired="True" />
                </telerik:TextBoxSetting>
            </telerik:RadInputManager>

        </telerik:RadAjaxPanel>

        <telerik:RadAjaxLoadingPanel ID="loadingPanel" runat="server" Transparency="30" BackColor="White"
            Width="967px">
            <asp:Image ID="Image1" runat="server" Style="margin-top: 150px" AlternateText="Loading"
                BorderWidth="0px" ImageUrl="../Images/ImageControl/loading.old.gif" />
        </telerik:RadAjaxLoadingPanel>
    </div>

</asp:Content>
